import lodash from 'lodash'

/**
 * script脚本树形文件夹数据tree处理
 */
export function createScriptTreeNode (tree) {
  return lodash.cloneDeep(tree).map((node) => {
    node.disabled = node.type === 'folder'
    if (node.scriptResults) {
      node.id = 'folder' + node.id
      node.children = node.scriptResults || []
      node.children.forEach(item => {
        item.name = `${item.name}（${item.code}）`
      })
    }
    return node
  })
}

/**
 * model模型树形文件夹数据tree处理
 */

export function createModelTreeNode (tree, idDisabled = '') {
  return lodash.cloneDeep(tree).map((node) => {
    node.disabled = node.type === 'folder'
    if (node.modelResults) {
      node.id = 'folder' + node.id
      node.children = node.modelResults || []
      node.children.forEach(item => {
        item.disabled = item.id == idDisabled
        item._id = item.id
        item.id = item.code
        item.name = `${item.name}（${item.code}）`
      })
    }
    return node
  })
}

export function createPageTreeNode (tree) {
  return lodash.cloneDeep(tree).map((node) => {
    node.disabled = node.type === 'folder'
    if (node.scriptResults) {
      node.id = 'folder' + node.id
      node.children = node.scriptResults || []
      node.children.forEach(item => {
        item.name = `${item.name}（${item.code}）`
      })
    }
    return node
  })
}

export function filterNodeMethod(value, data) {
  if (!value) return true
  return data.name && data.name.indexOf(value) !== -1
}
